import { WeaTools, WeaSearchGroup, WeaInput, WeaAlertPage } from 'ecCom';
import { Button, Modal, Table, Icon, Row, Col } from 'antd';
import { WeaFormItem } from 'ecCom';
import equal from 'deep-equal';
import WeaCrmShowGroup from '../comp/crm-show-group';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

class BusinessInfo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: props.data || {},
    };
  }
  shouldComponentUpdate(nextProps, nextState) {
    return !equal(this.state.data, nextState.data) ||
        !equal(this.props.hasright, nextProps.hasright);
  }
  componentWillReceiveProps(nextProps, nextState) {
    if (!equal(this.props.data, nextProps.data)) {
      this.setState({
        data: nextProps.data,
      });
    }
  }

  render() {
    const { data } = this.state;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    };
    const employeesColumns = [
      {
        title: getLabel(413, '姓名'),
        dataIndex: 'name',
        key: 'name',
      }, {
        title: getLabel(357, '职务'),
        dataIndex: 'job_title',
        key: 'job_title',
      },
    ];
    const branchesColumns = [
      {
        title: getLabel(195, '名称'),
        dataIndex: 'name',
        key: 'name',
      },
    ];
    const changerecordsColumns = [
      {
        title: getLabel(30284, '变更项目'),
        dataIndex: 'change_item',
        key: 'change_item',
      }, {
        title: getLabel(130778, '变更日期'),
        dataIndex: 'change_date',
        key: 'change_date',
        width: '120px',
      }, {
        title: getLabel(130779, '变更前内容'),
        dataIndex: 'before_content',
        key: 'before_content',
      }, {
        title: getLabel(130781, '变更后内容'),
        dataIndex: 'after_content',
        key: 'after_content',
      },
    ];
    const partnersColumns = [
      {
        title: getLabel(413, '姓名'),
        dataIndex: 'name',
        key: 'name',
      }, {
        title: getLabel(63, '类型'),
        dataIndex: 'stock_type',
        key: 'stock_type',
      },
    ];
    const abnormal_itemsColumns = [
      {
        title: getLabel(130784, '经营异常列入原因'),
        dataIndex: 'in_reason',
        key: 'in_reason',
      }, {
        title: getLabel(130785, '列入日期'),
        dataIndex: 'in_date',
        key: 'in_date',
      }, {
        title: getLabel(130786, '移出原因'),
        dataIndex: 'out_reason',
        key: 'out_reason',
      }, {
        title: getLabel(130787, '移出时间'),
        dataIndex: 'out_date',
        key: 'out_date',
      },
    ];
    const hasright = this.props.hasright != '';
    if (this.props.hasright) {
      return (<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@7gsum1`} >
        <div style={{ color: '#000' }}>
          {this.props.hasright}
        </div>
      </WeaAlertPage>
      );
    }
    return (
      <div>
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@9pe2bs`}
          leftComponent={getLabel(1361, '基本信息')}
          showGroup
          children={
            <div style={{ marginTop: '10px', paddingLeft: '30px' }} className="crm-business-form">
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@giaa04`}
                {...formItemLayout}
                label={getLabel(1976, '公司名称')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@bm4c8a`} viewAttr={1} hasBorder value={data.name} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@6k4s8u`}
                {...formItemLayout}
                label={getLabel(30976, '公司类型')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@1x95o5`} viewAttr={1} hasBorder value={data.econ_kind} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@srb4b5`}
                {...formItemLayout}
                label={getLabel(20668, '注册资本')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@vjq6dl`} viewAttr={1} hasBorder value={data.regist_capi} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@8iipv9`}
                {...formItemLayout}
                label={getLabel(110, '地址')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@474vgw`} viewAttr={1} hasBorder value={data.address} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@oxnux7`}
                {...formItemLayout}
                label={getLabel(130767, '企业注册号')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@6wg0qb`} viewAttr={1} hasBorder value={data.reg_no} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@iw85ru`}
                {...formItemLayout}
                label={getLabel(31031, '经营范围')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@yjqhj3`} viewAttr={1} hasBorder value={data.scope} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5ru8nq`}
                {...formItemLayout}
                label={getLabel(130768, '营业开始日期')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@oyymjc`} viewAttr={1} hasBorder value={data.term_start} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9syuzr`}
                {...formItemLayout}
                label={getLabel(130769, '营业结束日期')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@copcc1`} viewAttr={1} hasBorder value={data.term_end} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@tt1syh`}
                {...formItemLayout}
                label={getLabel(23797, '法人')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@34ceuc`} viewAttr={1} hasBorder value={data.oper_name} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9joacy`}
                {...formItemLayout}
                label={getLabel(27319, '成立日期')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@n9rc2o`} viewAttr={1} hasBorder value={data.start_date} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@k356z9`}
                {...formItemLayout}
                label={getLabel(130771, '注销日期')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@lozrwc`} viewAttr={1} hasBorder value={data.end_date} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ybj8a0`}
                {...formItemLayout}
                label={getLabel(130772, '核准日期')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@2uuhkt`} viewAttr={1} hasBorder value={data.check_date} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2ql22g`}
                {...formItemLayout}
                label={getLabel(130773, '在业')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@rqgeaf`} viewAttr={1} hasBorder value={data.status} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9k5bxq`}
                {...formItemLayout}
                label={getLabel(130774, '组织机构号')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@fj9clw`} viewAttr={1} hasBorder value={data.org_no} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@l437ye`}
                {...formItemLayout}
                label={getLabel(130775, '统一社会信用代码')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@c0m8zm`} viewAttr={1} hasBorder value={data.credit_no} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dgb2g8`}
                {...formItemLayout}
                label={getLabel(130776, '省份缩写')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@3xmag1`} viewAttr={1} hasBorder value={data.province} />
              </WeaFormItem>
              <WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@cnyxmw`}
                {...formItemLayout}
                label={getLabel(130777, '企业编号')}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@yhtfy4`} viewAttr={1} hasBorder value={data.id} />
              </WeaFormItem>
            </div>
          }
        />
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@41i3pz`}
          leftComponent={getLabel(130761, '主要成员')}
          showGroup
          children={
            <div style={{ paddingLeft: '30px', paddingRight: '30px' }}>
              <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@6a5x1z`} columns={employeesColumns} dataSource={data.employees} pagination={false} />
            </div>
          }
        />
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@r4jl8x`}
          leftComponent={getLabel(130762, '分支机构')}
          showGroup
          children={
            <div style={{ paddingLeft: '30px', paddingRight: '30px' }}>
              <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@gp4xy2`} columns={branchesColumns} dataSource={data.branches} pagination={false} />
            </div>
          }
        />
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@j68akl`}
          leftComponent={getLabel(130764, '变更信息')}
          showGroup
          children={
            <div style={{ paddingLeft: '30px', paddingRight: '30px' }}>
              <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@cltgy0`} columns={changerecordsColumns} dataSource={data.changerecords} pagination={false} />
            </div>
          }
        />
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@9egsic`}
          leftComponent={getLabel(27342, '股东信息')}
          showGroup
          children={
            <div style={{ paddingLeft: '30px', paddingRight: '30px' }}>
              <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@gd0uby`} columns={partnersColumns} dataSource={data.partners} pagination={false} />
            </div>
          }
        />
        <WeaCrmShowGroup
          ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmShowGroup@12tl6s`}
          leftComponent={getLabel(130763, '经营信息')}
          showGroup
          children={
            <div style={{ paddingLeft: '30px', paddingRight: '30px' }}>
              <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@1v9eik`} columns={abnormal_itemsColumns} dataSource={data.abnormal_items} pagination={false} />
            </div>
          }
        />
      </div>
    );
  }
}


export default BusinessInfo;
